﻿using Imaginecup.Recycling.Object;
using Imaginecup.Recycling.GameMan;
using Imaginecup.shareData;
using Imaginecup.util.resourceMan;
using Imaginecup.util.StaticValue;
using Imaginecup.gameState.recycling.Sprite.Behavior;

namespace Imaginecup.recycling.Object.Item
{
    public class ObjectFactory : IObjectFactory
    {
        #region 싱글톤으로 객체 생성 제한
        private static ObjectFactory Instance;

        public static ObjectFactory GetInstance()
        {
            if (Instance == null)
                Instance = new ObjectFactory();

            return Instance;
        }
        #endregion
        
        private IGameObject m_GameObject;
//        protected IManager m_Manager;
        private IPlayer m_tempPlayer;
//         public void SetManager(IManager manager)
//         {
//             m_Manager = manager;
//         }

        public IGameObject GetObject(ObjectID id)
        {
            switch(id)
            {
                case ObjectID.CLOUD:
                    m_GameObject = new MoveObject("cloud2", true);
                    break;
                case ObjectID.PLAYER:
                    m_GameObject = new Player();
                    m_tempPlayer = m_GameObject as IPlayer;
                    break;
                case ObjectID.JUMPBTN:
                    m_GameObject = new JumpButton(m_tempPlayer);
                    break;
                case ObjectID.SLIDINGBTN:
                    m_GameObject = new SlidingButton(m_tempPlayer);
                    break;
                case ObjectID.BACKGROUND_BACK:
                    CreateBackground("back_layer", Direction.None);
                    break;
                case ObjectID.BACKGROUND:
                    CreateBackground("background", Direction.Left);
                    break;
                case ObjectID.BACKGROUND_FRONT:
                    //CreateBackground("front_layer", Direction.Left);
                    CreateBackground("Background_front", Direction.Left);
                    break;
            }
 //           gameObject.SetManager(m_Manager);
            return m_GameObject;
        }

        private void CreateBackground(string name, Direction direction)
        {
            BackgroundTexture background = new BackgroundTexture();
            background.Texture = ResourceManager.GetInstance().GetContent(name);
            background.DisplayRange = StateShareData.GetShareData().GetGame().GraphicsDevice.Viewport.Bounds;
            background.ScrollDirection = direction;
            background.HorizontalSpeed = StaticValues.Speed;
            m_GameObject = background;
        }
    }
}
